package cn.wolfcode.shop.cloud.common;


import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class Result<T> {
    public static final Integer SUCCESS_CODE =200;
    public static final String SUCCESS_MSG = "操作成功";
    //错误码.
    public static final int DEFAULT_ERROR_CODE = 50001;
    //错误信息.
    public static final String DEFAULT_ERROR_MESSAGE = "系统异常";
    private Integer code;
    private String msg;
    private T data;

    public Result(Integer code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public Result() {
    }

    @Override
    public String toString() {
        return "Result{" +
                "code=" + code +
                ", msg='" + msg + '\'' +
                ", data=" + data +
                '}';
    }
    //操作成功
    public static Result success(Object data){
        return new Result(SUCCESS_CODE,SUCCESS_MSG,data);
    }
    //自定异常
    public static Result error(CodeMsg codeMsg){
        return new Result(codeMsg.getCode(),codeMsg.getMsg(),null);
    }
    //系统异常
    public static Result defaultError(){
        return new Result(DEFAULT_ERROR_CODE,DEFAULT_ERROR_MESSAGE,null);
    }

}
